<template>
  <div class="person">
    <h2>姓名：{{ name }}</h2>
    <h2>年龄：{{ age }}</h2>
    <button @click="changeName">修改姓名</button>
    <button @click="changeAge">修改年龄</button>
  </div>
</template>

<script lang="ts" setup name="Person">
import { reactive, toRefs, toRef } from "vue";
let person = reactive({
  name: "张三",
  age: 18,
});
// toRefs 和 toRef 把一个响应式对象里面的东西解构出来，并且让解构的变量拥有响应式能力
let { name, age } = toRefs(person);
let n1 = toRef(person, "age"); // 解构person中的age，且让age具有响应式

console.log(n1.value)

function changeName() {
  name.value += '~'
  console.log(name);
}
function changeAge() {
  age.value += 1;
  console.log(age);
}

</script>

<style>
.person {
  background-color: turquoise;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
button {
  margin: 0 5px;
}
</style>
